package com.tunan.lsj.business.building.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import javax.validation.Valid;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.EasyUiPage;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.tunan.common.Result;
import com.tunan.common.resultSub.ResultSuccess;
import com.tunan.lsj.business.building.service.GgFwxxzService;
import com.tunan.lsj.business.town.service.JzdmService;
import com.tunan.persistence.model.GgFwxxz;
import com.tunan.persistence.model.TJzdm;
import com.tunan.system.dic.service.IBscDicCodeService;
import com.tunan.system.persistence.model.BscDicCodeItem;
import com.tunan.system.service.IdentifierGenerator;
import com.tunan.system.web.BaseController;
import com.tunan.utils.Obj2Map;
import com.tunan.utils.StringHelper;
import com.tunan.utils.StringUtils;

@RestController
public class GgFwxxzController extends BaseController {
	@Autowired
	private IBscDicCodeService bscDicCodeService;

	@Autowired
	private GgFwxxzService ggFwxxzService;

	@Autowired
	private JzdmService jdmService;

	private Logger log = Logger.getLogger(GgFwxxzController.class);

	@RequestMapping(value = "/lsj/building/buildingList", method = RequestMethod.GET)
	public ModelAndView buildingList() {
		return new ModelAndView("/lsj/building/building-list");
	}

	/**
	 * 
	 * @param pageParams
	 * @param wfds
	 * @return EasyUiPage
	 * @Description
	 * @date 2016年4月6日
	 * @author kinda
	 */
	@RequestMapping(value = "/lsj/building/	search2", method = RequestMethod.POST)
	@ResponseBody
	public EasyUiPage search(@ModelAttribute("pageParams") Page<?> pageParams, GgFwxxz ggFwxxz) {
		PageHelper.startPage(pageParams.getPageNum(), pageParams.getPageSize());
		Page<?> pageresult = (Page<?>) ggFwxxzService.selectAll(ggFwxxz);
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("ggFwxxz",ggFwxxz);

		EasyUiPage page = pageresult.getEasyUiPage();
		List rows = page.getRows();
		for (Object f : rows) {
			GgFwxxz ff = (GgFwxxz) f;
			System.out.println(ff.getXzq());
		}
		
		return pageresult.getEasyUiPage();
	}

	@RequestMapping(value = "/lsj/building/conditionSearch", method = RequestMethod.GET)
	public ModelAndView searchPage(@ModelAttribute("ggFwxxz") GgFwxxz ggFwxxz, ModelAndView modelAndView) {
		modelAndView.setViewName("/lsj/building/building-search");
		return modelAndView;
	}

	/**
	 * 进入编辑界面
	 * 
	 * @param id
	 * @return
	 */
	// @RequestMapping(value = "/lsj/building/showModify", method =
	// RequestMethod.GET)
	// public ModelAndView showModify(String id){
	// ModelAndView model = new ModelAndView();
	// try {
	// if(StringUtils.isNotBlank(id)){
	// TJzdm form = jdmService.selectOne(id);
	// model.addObject("vo",form);
	// }
	// } catch (Exception e) {
	// log.error(e.getMessage(), e);
	// }
	// model.setViewName("/lsj/building/building-edit");
	// return model;
	// }

	// /**
	// * 保存
	// * @param tJzdm
	// * @return
	// */
	// @RequestMapping(value = "/lsj/town/save", method = RequestMethod.POST)
	// @ResponseBody
	// public Result save(@ModelAttribute("tJzdm") TJzdm tJzdm) {
	// ResultSuccess rs = new ResultSuccess();
	// ResultFailure rf = new ResultFailure();
	// try {
	// if (tJzdm != null) {
	// if (StringUtils.isNotBlank(tJzdm.getDm())) {
	// jdmService.update(tJzdm);
	// rs.setMessage("修改成功");
	// } else {
	// tJzdm.setDm(identifierGenerator.generate());
	// jdmService.insert(tJzdm);
	// rs.setMessage("新增成功");
	// }
	// }
	// return rs;
	//
	// } catch (Exception e) {
	// e.printStackTrace();
	// log.error(e.getMessage(), e);
	// }
	// rf.setMessage("操作失败");
	// return rf;
	// }
	//
	// /**
	// * 删除
	// *
	// * @param user
	// * @return
	// */
	// @RequestMapping(value = "/lsj/town/delete", method = RequestMethod.POST)
	// @ResponseBody
	// public Result delete(String id) {
	// try {
	// if (StringUtils.isNotBlank(id)) {
	// jdmService.delete(id);
	// }
	// return new ResultSuccess("删除成功");
	// } catch (Exception e) {
	// e.printStackTrace();
	// log.error(e.getMessage(), e);
	// }
	// return new ResultFailure("删除失败");
	// }
	//
	// /**
	// * 批量删除
	// *
	// * @param user
	// * @return
	// */
	// @RequestMapping(value = "/lsj/town/batchDel", method =
	// RequestMethod.POST)
	// public Result batchDel(String ids) {
	// try {
	// if (StringUtils.isNotBlank(ids)) {
	// List<String> idList = new ArrayList<String>();
	// if (ids.contains(",")) {
	// idList = Arrays.asList(ids.split(","));
	// } else {
	// idList.add(ids);
	// }
	// jdmService.batchDel(idList);
	// }
	// return new ResultSuccess("批量删除成功");
	// } catch (Exception e) {
	// e.printStackTrace();
	// log.error(e.getMessage(), e);
	// }
	// return new ResultFailure("批量删除失败");
	// }
}
